<template>
  <!--批量活动执行情况查询 经销商端 参与车辆明细-->
  <div>
    <FilterTable
      :onSyncTableData="tableChange"
      :isSelectColumn="false"
      :isExportExcel="true"
      :dataSource="dataList"
      :isMemoryPagination="true"
      height="400"
      exportFileName="参与车辆明细.xlsx"
      :onCalcExportData="handleExportFun"
      :onRowSelectChange="selectChange"
      ref="table"
      :columns="columns"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>

    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="closeMenu(2)">关闭 </el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { isEmpty } from '@/utils/utils';
import { getCondition } from '@/api/repair/batchEventManagement/activityExecutionStatusQueryJingxsDuan';
import { arrayObjDeWeight } from '@/utils';
import { dealerMixin } from '@/pages/repair/batchEventManagement/dealerMixin';

export default {
  name: 'addItem',
  mixins: [dictionary, dealerMixin],
  props: ['id'],
  data() {
    this.BaseTable = null;
    this.conf = { add: '新增', edit: '编辑', show: '审核' };
    return {
      visible: false,
      dataList: [],
      fetchApi: getCondition,
      dialogTitle: '',
      fetchParams: { xhrAbort: true, id: this.id },
      columns: this.createTableColumns(),
      selectArr: []
    };
  },
  components: {},

  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;

    // this.getAllUsers(this.columns, ['serviceAdvisorAss', 'serviceAdvisor'], 'table');

    this.getBrand(this.columns, ['brand'], 'table');

    this.getSeries(this.columns, ['series'], 'table');

    this.getAllModels(this.columns, ['model'], 'table');

    this.getList();
  },
  methods: {
    dealerTranslate() {
      let userIds = [];
      this.tableData.forEach(item => {
        userIds.push(item.serviceAdvisor);
        userIds.push(item.serviceAdvisorAss);
      });
      if (!userIds.length) return;
      let newUserIds = Array.from(new Set(userIds)); // 数组去重
      this.getNameByIds(this.columns, newUserIds.join(','), ['serviceAdvisorAss', 'serviceAdvisor'], 'table');
    },
    tableChange(data) {
      this.tableData = data;
      this.dealerTranslate();
    },
    handleExportFun() {},

    async getList() {
      let res = await getCondition({ id: this.id });
      if (res.resultCode == 200 && res.success == true) {
        let data = isEmpty(res['data']) ? [] : res['data'];

        this.BaseTable.EXECUTE_INSERT(data);
      }
      // this.dataList = [...this.dataList, ...data];
    },

    selectChange(val) {
      this.selectArr = val;
      console.log(val);
    },

    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'maNo',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '工单号',
          dataIndex: 'roNo',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户编号',
          dataIndex: 'ownerNo',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发动机号',
          dataIndex: 'engineNo',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'brand',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: []
        },
        {
          title: '车系',
          dataIndex: 'series',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: []
        },
        {
          title: '车型',
          dataIndex: 'model',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: []
        },
        {
          title: '送修人',
          dataIndex: 'deliverer',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修人手机',
          dataIndex: 'delivererMobile',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '服务顾问',
          dataIndex: 'serviceAdvisor',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        {
          title: '创建人',
          dataIndex: 'serviceAdvisorAss',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        {
          title: '参与活动时间',
          dataIndex: 'roCreateDate',
          width: 150,
          sorter: true,
          filter: true,
          filterType: 'date-range'
        }
      ];
    },

    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    async closeMenu(type) {
      this.$emit('close');
    }
  }
};
</script>

<style lang="less" scoped>
.bg1 {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
  padding-left: 0;
  padding-top: 15px;
  padding-bottom: 15px;
}

.bg2 {
  margin-top: 10px;
  margin-bottom: 10px;
}

.btn {
  text-align: center;
}

.btnStyle {
  margin-top: 10px;
}
</style>
